<%@ page contentType="text/html; charset=UTF-8" language="java" %>
<%@ include file="/taglibs.jsp" %>
<head>
<title>
	<s:if test="%{user.id==null}">
		<s:text name="module.user.createUser"/>
	</s:if>
	<s:else>
		<s:text name="module.user.editUser"/>
	</s:else>
</title>
<script type="text/javascript">
$(function() {
	$("form").themingForm();
	$("#save, #saveAndNew, #cancel" ).button();
	$("#save").click(function(){
						if($("#newForm").valid()) {
							newForm.action="user!create.action";
							newForm.submit();
						}});
	$("#saveAndNew").click(function(){
		if($("#newForm").valid()) {
			newForm.action="user!createAndNew.action";
			newForm.submit();
		}});
	$("#cancel").click(function(){window.location='user!index.action';});
	
	$("#newForm").validate({
        rules: { 
		    'user.userName': {remote:"user!checkUniqueness.action?uniqueField=userName"}
        },
		onkeyup: false,
		messages: {
			'user.userName': {//required: " ",
				remote: jQuery.validator.format("<s:text name='error.uniqueConstraint'/>")	
			}
		}
	});
	
	/* jqgrid in pop up select box 
	jQuery("#list").jqGrid( {
		url : 'catalog!catalogJsonList.action',
		datatype : "json",
		prmNames : {
			page : "jq.requestPage", rows : "jq.pageSize", sort : "jq.sortColumn",
			order : "jq.sortDirection", search : "jq._search", nd : "jq.nd", npage : null},
		jsonReader : {
			root : "rows", repeatitems : false, id : "0"},
		colNames : [ '<s:text name="module.common.id"/>',
					 '<s:text name="module.catalog.catalogId"/>', 
		 			 '<s:text name="module.catalog.catalogName"/>', 
		 			 '<s:text name="module.catalog.parentCatalogName"/>'],
		colModel : [ {name : 'id',index : 'id', width : 20, hidden:true}, 
					 {name : 'catalogId',index : 'catalogId', width : 140},
		     		 {name : 'catalogName',index : 'catalogName',width : 180},
		     		 {name : 'parentCatalog.catalogName', sortable : false,width : 180}],		
		rowNum : 15,
		rowList : [15,30,50],
		height: 'auto',
		pager : '#pager',
		sortname : 'catalogId',
		viewrecords: true,
		sortorder : 'asc',
		loadOnce : true,
		caption : false
	});
	jQuery("#list").jqGrid('filterToolbar',{stringResult: true,searchOnEnter : false});
	*/

	/* popup select box fo parent catalog
	$( "#popupDialogSelectBox" ).dialog({
		autoOpen: false,
		height: 400,
		width: 520,
		modal: true,
		buttons: {
			"Select": function() {
				var id = jQuery("#list").jqGrid('getGridParam','selrow');
				if (id)	{
					var ret = jQuery("#list").jqGrid('getRowData',id);
					$("#parentCatalogId").attr("value",ret.id);
					$("#parentCatalogName").attr("value",ret.catalogName);
					$( this ).dialog( "close" );
				} else { alert("Please select row");}
				$( this ).dialog( "close" );
			},
			Cancel: function() {
				$( this ).dialog( "close" );
			}
		},
		close: function() {
			allFields.val( "" ).removeClass( "ui-state-error" );
		}
	});*/
});//end


</script>
</head>
<body>
<h2>
	<s:if test="%{user.id==null}">
		<s:text name="module.user.createUser"/>
	</s:if>
	<s:else>
		<s:text name="module.user.editUser"/>
	</s:else>
</h2>


<div id="popupDialogSelectBox" title="Select a parent catalog">
<table id="list"></table>
<div id="pager"></div>
</div>
<%System.out.println(""); %>
<div class="ui-helper-clearfix">
	<button id="save"><s:text name="button.save"/></button>
	<button id="saveAndNew"><s:text name="button.saveAndNew"/></button>
	<button id="cancel"><s:text name="button.cancel"/></button>
</div>
<form id="newForm" action="user!create.action" validate="true" autocomplete="off" method="POST">
	<table width="95%">
		<colgroup span="4" width="25%" >
		</colgroup>
		<tbody>
			<tr>
				<td class="label mandatory">
					<s:label key="module.user.userName" for="userName"/></td>
				<td style="vertical-align:top;padding-top:4">
					<s:textfield id="userName" name="user.userName" maxlength="50" cssClass="required" /></td>
				<td class="label mandatory">
					<s:label key="module.user.isEnabled" for="isEnabled"/></td>
				<td class="element">
				<s:select id="isEnabled" name="user.isEnabled" list="#application['SELECT_YES_NO']" value="user.isEnabled" cssClass="required"/>
			</tr>
			<tr>
				<td class="label mandatory">
					<s:label key="module.user.password" for="password"/></td>
				<td style="vertical-align:top;padding-top:4">
					<s:password id="password" name="user.password" maxlength="50" cssClass="required" /></td>
				<td class="label mandatory">
					<s:label key="module.user.confirmPassword" for="confirmPassword"/></td>
				<td class="element">
				<s:password id="confirmPassword" name="user.confirmPassword" cssClass="required"/>
			</tr>
			<tr>
				<td class="label">
					<s:label key="module.user.preferedLanguage" for="preferedLanguage"/></td>
				<td>
					<s:textfield  id="preferedLanguage" name="user.preferedLanguage"/>
					</td>
				<td></td>
				<td></td>
			</tr>
			<tr>
				<td class="label">
					<s:label key="module.common.description" for="description"/></td>
				<td colspan="3">
					<s:textarea  id="description" label="" name="user.description" rows="5" cols="105"/>
			</tr>
	
		</tbody>
	</table>
</form>
<script type="text/javascript">

</script>	
</body>
